{"ast":null,"code":"import _slicedToArray from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";import React from'react';import{getLastMessage,getUserNameLastMessage}from\"../../utils/Chat\";import{getHelloMessage}from\"../../utils/Message\";import{getOtherUserForNotMultiChat}from\"../../utils/Membership\";import{getUserName}from\"../../utils/User\";import{MessageDate,MessageStatus,Avatar,Name}from\"../\";import{Context}from\"../../index\";import classNames from\"classnames\";import{observer}from\"mobx-react-lite\";import'./Dialog.scss';import{jsx as _jsx}from\"react/jsx-runtime\";import{jsxs as _jsxs}from\"react/jsx-runtime\";var DialogItem=function DialogItem(_ref){var _lastMessage$bodyMess;var chat=_ref.chat;var _React$useContext=React.useContext(Context),store=_React$useContext.store;var _React$useState=React.useState(),_React$useState2=_slicedToArray(_React$useState,2),otherUser=_React$useState2[0],setOtherUser=_React$useState2[1];var _React$useState3=React.useState(false),_React$useState4=_slicedToArray(_React$useState3,2),viewedDialog=_React$useState4[0],setViewedDialog=_React$useState4[1];var _React$useState5=React.useState(chat.lastMessage||getHelloMessage(store)),_React$useState6=_slicedToArray(_React$useState5,2),lastMessage=_React$useState6[0],setLastMessage=_React$useState6[1];React.useEffect(function(){if(!chat.multiChat&&chat.membership&&chat.membership.items.length>0){setOtherUser(getOtherUserForNotMultiChat(store,chat.membership));}if(chat.messages&&chat.messages.items.length>0){setLastMessage(getLastMessage(chat.messages));}else{setLastMessage(getHelloMessage(store));}if(store.viewedDialogId===chat.id){setViewedDialog(true);}else{setViewedDialog(false);}},[chat,store.chats,store.viewedDialogId]);return/*#__PURE__*/_jsxs(\"div\",{className:classNames('dialogs__item',{'dialogs__item--online':!chat.multiChat,'dialogs__item--active':viewedDialog}),onClick:function onClick(){if(store.getViewedDialogId()===chat.id){store.setViewedDialogId(null);}else{store.setCurrentDialog(chat);store.setViewedDialogId(chat.id);}},children:[/*#__PURE__*/_jsxs(\"div\",{className:\"dialogs__item--avatar\",children:[chat.multiChat&&/*#__PURE__*/_jsx(Avatar,{contentList:chat.content,alt:chat.name,stringForFirstCharacter:chat.name,stringForGenerateColor:chat.name}),!chat.multiChat&&otherUser&&/*#__PURE__*/_jsx(Avatar,{contentList:otherUser.content,alt:getUserName(otherUser),stringForFirstCharacter:getUserName(otherUser),stringForGenerateColor:otherUser.id})]}),/*#__PURE__*/_jsxs(\"div\",{className:\"dialogs__item-info\",children:[/*#__PURE__*/_jsxs(\"div\",{className:\"dialogs__item-info-top\",children:[/*#__PURE__*/_jsx(\"p\",{className:\"dialogs__item-chatName\",children:/*#__PURE__*/_jsx(Name,{user:otherUser,chatName:chat.name,multiChat:chat.multiChat})}),chat.messages&&chat.messages.items.length>0&&/*#__PURE__*/_jsx(MessageDate,{message:lastMessage,shortDate:true})]}),chat.multiChat&&lastMessage&&/*#__PURE__*/_jsx(\"div\",{className:\"dialogs__item-info-medium\",children:/*#__PURE__*/_jsx(\"p\",{children:getUserNameLastMessage(lastMessage.user,store)})}),/*#__PURE__*/_jsxs(\"div\",{className:\"dialogs__item-info-bottom\",children:[/*#__PURE__*/_jsx(\"p\",{children:lastMessage===null||lastMessage===void 0?void 0:(_lastMessage$bodyMess=lastMessage.bodyMessage)===null||_lastMessage$bodyMess===void 0?void 0:_lastMessage$bodyMess.message}),lastMessage&&/*#__PURE__*/_jsx(MessageStatus,{message:lastMessage,store:store,dialog:true}),chat.unreadMessageCounter!==0&&/*#__PURE__*/_jsx(\"div\",{className:\"dialogs__item-info-bottom-count\",children:chat.unreadMessageCounter&&chat.unreadMessageCounter>9?'+9':chat.unreadMessageCounter})]})]})]});};export default observer(DialogItem);","map":{"version":3,"names":["React","getLastMessage","getUserNameLastMessage","getHelloMessage","getOtherUserForNotMultiChat","getUserName","MessageDate","MessageStatus","Avatar","Name","Context","classNames","observer","DialogItem","chat","useContext","store","useState","otherUser","setOtherUser","viewedDialog","setViewedDialog","lastMessage","setLastMessage","useEffect","multiChat","membership","items","length","messages","viewedDialogId","id","chats","getViewedDialogId","setViewedDialogId","setCurrentDialog","content","name","user","bodyMessage","message","unreadMessageCounter"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/components/DialogItem/index.tsx"],"sourcesContent":["import React from 'react';\nimport {DialogsItemProps} from \"../../models/props/DialogsItemProps\";\nimport {getLastMessage, getUserNameLastMessage} from \"../../utils/Chat\";\nimport {getHelloMessage} from \"../../utils/Message\";\nimport {getOtherUserForNotMultiChat} from \"../../utils/Membership\";\nimport {getUserName} from \"../../utils/User\";\nimport {MessageDate, MessageStatus, Avatar, Name} from \"../\";\nimport {MessagesListItem} from \"../../models/response/MessagesListItem\";\nimport {UserListItem} from \"../../models/response/UserListItem\";\nimport {Context} from \"../../index\";\nimport classNames from \"classnames\";\nimport {observer} from \"mobx-react-lite\";\nimport './Dialog.scss';\n\nconst DialogItem: React.FC<DialogsItemProps> = ({chat}) => {\n    const {store} = React.useContext(Context);\n    const [otherUser, setOtherUser] = React.useState<UserListItem>();\n    const [viewedDialog, setViewedDialog] = React.useState<boolean>(false);\n    const [lastMessage, setLastMessage] = React.useState<MessagesListItem>(\n        (chat.lastMessage || getHelloMessage(store))\n    );\n\n    React.useEffect(() => {\n            if (!chat.multiChat && chat.membership && chat.membership.items.length > 0) {\n                setOtherUser(getOtherUserForNotMultiChat(store, chat.membership));\n            }\n            if (chat.messages && chat.messages.items.length > 0) {\n                setLastMessage(getLastMessage(chat.messages));\n            } else {\n                setLastMessage(getHelloMessage(store));\n            }\n            if (store.viewedDialogId === chat.id) {\n                setViewedDialog(true);\n            } else {\n                setViewedDialog(false);\n            }\n    }, [chat, store.chats, store.viewedDialogId]);\n\n    return (\n        <div\n            className={classNames('dialogs__item', {\n                'dialogs__item--online' : !chat.multiChat,\n                'dialogs__item--active': viewedDialog\n            })}\n            onClick={() => {\n                if (store.getViewedDialogId() === chat.id) {\n                    store.setViewedDialogId(null);\n                } else {\n                    store.setCurrentDialog(chat);\n                    store.setViewedDialogId(chat.id);\n                }\n            }}\n        >\n            <div className=\"dialogs__item--avatar\">\n                {chat.multiChat &&\n                    <Avatar\n                        contentList={chat.content}\n                        alt={chat.name}\n                        stringForFirstCharacter={chat.name}\n                        stringForGenerateColor={chat.name}\n                    />\n                }\n                {!chat.multiChat && otherUser &&\n                    <Avatar\n                        contentList={otherUser.content}\n                        alt={getUserName(otherUser)}\n                        stringForFirstCharacter={getUserName(otherUser)}\n                        stringForGenerateColor={otherUser.id}\n                    />\n                }\n            </div>\n            <div className=\"dialogs__item-info\">\n                <div className=\"dialogs__item-info-top\">\n                   <p className='dialogs__item-chatName'>\n                       <Name user={otherUser} chatName={chat.name} multiChat={chat.multiChat} />\n                   </p>\n                   {\n                       (chat.messages && chat.messages.items.length > 0) && <MessageDate message={lastMessage} shortDate={true} />\n                    }\n                </div>\n                {chat.multiChat && lastMessage &&\n                    <div className='dialogs__item-info-medium'>\n                        <p>{getUserNameLastMessage(lastMessage.user, store)}</p>\n                    </div>\n                }\n                <div className=\"dialogs__item-info-bottom\">\n                    <p>{lastMessage?.bodyMessage?.message}</p>\n                    {lastMessage && <MessageStatus message={lastMessage} store={store} dialog={true} />}\n                    {chat.unreadMessageCounter !== 0 &&\n                        <div className=\"dialogs__item-info-bottom-count\">\n                            {(chat.unreadMessageCounter && chat.unreadMessageCounter > 9)? '+9': chat.unreadMessageCounter}\n                        </div>\n                    }\n                </div>\n            </div>\n        </div>\n    );\n}\n\nexport default observer(DialogItem);"],"mappings":"8IAAA,MAAOA,MAAK,KAAM,OAAO,CAEzB,OAAQC,cAAc,CAAEC,sBAAsB,KAAO,kBAAkB,CACvE,OAAQC,eAAe,KAAO,qBAAqB,CACnD,OAAQC,2BAA2B,KAAO,wBAAwB,CAClE,OAAQC,WAAW,KAAO,kBAAkB,CAC5C,OAAQC,WAAW,CAAEC,aAAa,CAAEC,MAAM,CAAEC,IAAI,KAAO,KAAK,CAG5D,OAAQC,OAAO,KAAO,aAAa,CACnC,MAAOC,WAAU,KAAM,YAAY,CACnC,OAAQC,QAAQ,KAAO,iBAAiB,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